package com.store.framework.db;

import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.dao.IAppRootMapDao;
import com.store.framework.entry.RootMap;

public class AppRootMapDao implements IAppRootMapDao {
	private static Log LOG = LogFactory.getLog(AppRootMapDao.class);

	@Override
	public int Add(RootMap rm) {
		// TODO Auto-generated method stub
		int r = 0;
		String sql = "insert into app_rootmap(Id,RootId,AdminId,AdName,AdCode,"
				+ "RootName,RootCode,Domain,Url,Param,SAddDate,SaddPer,EditDate,"
				+ "EditPer,DelDate,DelPer,Del,Remarks) value(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			DaoUtil.executeUpdate(sql, rm.getId(), rm.getRootId(),
					rm.getAdminId(), rm.getAdName(), rm.getAdcode(),
					rm.getRootName(), rm.getRootCode(), rm.getDomain(),
					rm.getUrl(), rm.getParam(), rm.getAddDate(),
					rm.getSaddPer(), rm.getEditDate(), rm.getEditPer(),
					rm.getDelDate(), rm.getDelPer(), rm.getDel(),
					rm.getRemarks());
			r = 1;
		} catch (Exception e) {
			r = 0;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return r;
	}

	@Override
	public List<RootMap> select() {
		// TODO Auto-generated method stub
		List<RootMap> list = new ArrayList<RootMap>();
		String sql = "select * from app_rootmap";
		RootMap rootmap = new RootMap();
		try {
			CachedRowSet ct = DaoUtil.SimpleQuery(sql);
			while (ct.next()) {
				rootmap.setId(ct.getString("Id"));
				rootmap.setRootId(ct.getString("RootId"));
				rootmap.setAdminId(ct.getString("AdminId"));
				rootmap.setAdName(ct.getString("AdName"));
				rootmap.setAdcode(ct.getString("Adcode"));
				rootmap.setRootName(ct.getString("RootName"));
				rootmap.setRootCode(ct.getString("RootCode"));
				rootmap.setDomain(ct.getString("Domain"));
				rootmap.setUrl(ct.getString("Url"));
				rootmap.setParam(ct.getString("Param"));
				rootmap.setAddDate(ct.getDate("SAddDate"));
				rootmap.setSaddPer(ct.getString("SaddPer"));
				rootmap.setEditDate(ct.getDate("EditDate"));
				rootmap.setEditPer(ct.getString("EditPer"));
				rootmap.setDelDate(ct.getDate("DelDate"));
				rootmap.setDelPer(ct.getString("DelPer"));
				rootmap.setDel(ct.getByte("Del"));
				rootmap.setRemarks(ct.getString("Remarks"));
				list.add(rootmap);
			}
		} catch (Exception e) {
			list = null;
			LOG.error(e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
		return list;
	}

}
